package com.jxw.gk;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import com.jxw.launcher.util.Logger;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes.dex */
public class ControlSyncInfo {
    public static final String ANDROID_APP_LIST = "app_list";
    public static final String ANDROID_ENTRANCE = "android_entrance";
    public static final String APP_DISABLE = "app_name";
    public static final String APP_DISABLE_STATUS = "app_status";
    public static final String APP_MARKET_ENTRANCE = "app_market_entrance";
    public static final String APP_REMAIN_USE_TIME = "app_remain_time";
    public static final String CURRENT_GK_VERSION = "gk_version";
    public static String TABLE_APP_LIST = "app_list_table";
    public static final Uri CONTROL_APP_LIST = Uri.parse("content://com.jxw.utils.provider/" + TABLE_APP_LIST);
    public static String TABLE_ANDROID_OPEN = "android_open_table";
    public static final Uri CONTROL_ANDROID = Uri.parse("content://com.jxw.utils.provider/" + TABLE_ANDROID_OPEN);
    public static String TABLE_MARKET_OPEN = "market_open_table";
    public static final Uri CONTROL_MARKET = Uri.parse("content://com.jxw.utils.provider/" + TABLE_MARKET_OPEN);
    public static String TABLE_APP_DISABLE = "app_disable";
    public static final Uri CONTROL_APP_DISABLE = Uri.parse("content://com.jxw.utils.provider/" + TABLE_APP_DISABLE);
    public static String TABLE_GK_VERSION = "gk_version";
    public static final Uri CONTROL_GK_VERSION = Uri.parse("content://com.jxw.utils.provider/" + TABLE_GK_VERSION);

    public static void saveAndroidEntrance(Context context, int i) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(ANDROID_ENTRANCE, Integer.valueOf(i));
        saveFixInfo(context, contentValues, CONTROL_ANDROID, null);
    }

    public static void saveAppMarketEntrance(Context context, int i) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(APP_MARKET_ENTRANCE, Integer.valueOf(i));
        saveFixInfo(context, contentValues, CONTROL_MARKET, null);
    }

    public static void saveAppDisable(Context context, GKAppBean gKAppBean) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(APP_DISABLE, gKAppBean.getPkgName());
        contentValues.put(APP_DISABLE_STATUS, Integer.valueOf(gKAppBean.getStatus()));
        contentValues.put(APP_REMAIN_USE_TIME, Integer.valueOf(gKAppBean.getTime()));
        Logger logger = Logger.getLogger();
        logger.e("gkAppBean:" + gKAppBean.toString());
        saveFixInfo(context, contentValues, CONTROL_APP_DISABLE, "app_name=" + gKAppBean.getPkgName());
    }

    public static void saveGKAppList(Context context, String str) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_list", str);
        saveFixInfo(context, contentValues, CONTROL_APP_LIST, null);
    }

    private static void saveFixInfo(Context context, ContentValues contentValues, Uri uri, String str) {
        if (hasExist(context, uri, str)) {
            int update = context.getContentResolver().update(uri, contentValues, null, null);
            Logger logger = Logger.getLogger();
            logger.e("saveFixInfo update:" + update);
            return;
        }
        context.getContentResolver().insert(uri, contentValues);
    }

    public static boolean getAndroidOpen(Context context) {
        return Integer.parseInt(getQueryUri(context, CONTROL_ANDROID, ANDROID_ENTRANCE, null)) == 1;
    }

    public static boolean getMarketOpen(Context context) {
        return Integer.parseInt(getQueryUri(context, CONTROL_MARKET, APP_MARKET_ENTRANCE, null)) == 1;
    }

    public static List<GKAppBean> getAppDisableList(Context context) {
        return getQueryUriObj(context, CONTROL_APP_DISABLE, APP_DISABLE, null);
    }

    public static String getGKVersion(Context context) {
        return getQueryUri(context, CONTROL_GK_VERSION, CURRENT_GK_VERSION, null);
    }

    public static void saveGKVersion(Context context) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(CURRENT_GK_VERSION, "version6");
        saveFixInfo(context, contentValues, CONTROL_GK_VERSION, null);
    }

    public static GKAppBean getAppDisable(Context context, String str) {
        GKAppBean gKAppBean;
        List<GKAppBean> queryUriObj = getQueryUriObj(context, CONTROL_APP_DISABLE, APP_DISABLE, "app_name= '" + str + "'");
        if (queryUriObj.size() > 0) {
            gKAppBean = queryUriObj.get(0);
            Logger logger = Logger.getLogger();
            logger.e("-----getAppDisable:" + gKAppBean.toString());
        } else {
            gKAppBean = null;
        }
        Logger.getLogger().e("-----getAppDisable: null");
        return gKAppBean;
    }

    public static String getGKAppList(Context context) {
        return getQueryUri(context, CONTROL_APP_LIST, "app_list", null);
    }

    private static List<GKAppBean> getQueryUriObj(Context context, Uri uri, String str, String str2) {
        Logger logger = Logger.getLogger();
        logger.e("getQueryUri uriString:" + uri + ",column:" + str + ",selection:" + str2);
        ArrayList arrayList = new ArrayList();
        try {
            Cursor query = context.getContentResolver().query(uri, null, str2, null, null);
            if (query != null && query.getCount() > 0) {
                while (query.moveToNext()) {
                    new GKAppBean();
                    GKAppBean gKAppBean = new GKAppBean();
                    gKAppBean.setPkgName(query.getString(query.getColumnIndex(APP_DISABLE)));
                    gKAppBean.setStatus(query.getInt(query.getColumnIndex(APP_DISABLE_STATUS)));
                    gKAppBean.setTime(query.getInt(query.getColumnIndex(APP_REMAIN_USE_TIME)));
                    Logger logger2 = Logger.getLogger();
                    logger2.e("getQueryUri--:" + gKAppBean.toString());
                    arrayList.add(gKAppBean);
                }
            }
            if (query != null) {
                query.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arrayList;
    }

    private static String getQueryUri(Context context, Uri uri, String str, String str2) {
        Logger logger = Logger.getLogger();
        logger.e("getQueryUri uriString:" + uri + ",column:" + str);
        String str3 = "";
        try {
            Cursor query = context.getContentResolver().query(uri, null, str2, null, null);
            if (query != null && query.getCount() > 0) {
                while (query.moveToNext()) {
                    str3 = query.getString(query.getColumnIndex(str));
                }
            }
            if (query != null) {
                query.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (TextUtils.isEmpty(str3)) {
            str3 = "0";
        }
        Logger logger2 = Logger.getLogger();
        logger2.e("getQueryUri:" + str3);
        return str3;
    }

    /* JADX WARN: Code restructure failed: missing block: B:10:0x001c, code lost:
        r8.close();
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static boolean hasExist(android.content.Context r8, android.net.Uri r9, java.lang.String r10) {
        /*
            r0 = 0
            android.content.ContentResolver r1 = r8.getContentResolver()     // Catch: java.lang.Exception -> L1f
            r3 = 0
            r5 = 0
            r6 = 0
            r7 = 0
            r2 = r9
            r4 = r10
            android.database.Cursor r8 = r1.query(r2, r3, r4, r5, r6, r7)     // Catch: java.lang.Exception -> L1f
            r9 = 1
            if (r8 == 0) goto L1a
            int r10 = r8.getCount()     // Catch: java.lang.Exception -> L1f
            if (r10 >= r9) goto L19
            goto L1a
        L19:
            r0 = 1
        L1a:
            if (r8 == 0) goto L1f
            r8.close()     // Catch: java.lang.Exception -> L1f
        L1f:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.jxw.gk.ControlSyncInfo.hasExist(android.content.Context, android.net.Uri, java.lang.String):boolean");
    }
}
